package com.ruoyi.experiment.service.impl;

import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.experiment.mapper.ExperimentAnalysisMapper;
import com.ruoyi.experiment.domain.ExperimentAnalysis;
import com.ruoyi.experiment.service.IExperimentAnalysisService;

/**
 * 数据分析Service业务层处理
 * 
 * @author gw
 * @date 2025-01-08
 */
@Service
public class ExperimentAnalysisServiceImpl implements IExperimentAnalysisService 
{
    @Autowired
    private ExperimentAnalysisMapper experimentAnalysisMapper;

    /**
     * 查询数据分析
     * 
     * @param analysisId 数据分析主键
     * @return 数据分析
     */
    @Override
    public ExperimentAnalysis selectExperimentAnalysisByAnalysisId(Long analysisId)
    {
        return experimentAnalysisMapper.selectExperimentAnalysisByAnalysisId(analysisId);
    }

    /**
     * 查询数据分析列表
     * 
     * @param experimentAnalysis 数据分析
     * @return 数据分析
     */
    @Override
    public List<ExperimentAnalysis> selectExperimentAnalysisList(ExperimentAnalysis experimentAnalysis)
    {
        return experimentAnalysisMapper.selectExperimentAnalysisList(experimentAnalysis);
    }

    /**
     * 新增数据分析
     * 
     * @param experimentAnalysis 数据分析
     * @return 结果
     */
    @Override
    public int insertExperimentAnalysis(ExperimentAnalysis experimentAnalysis)
    {
        experimentAnalysis.setCreateTime(DateUtils.getNowDate());
        experimentAnalysis.setCreateBy(SecurityUtils.getUsername());
        return experimentAnalysisMapper.insertExperimentAnalysis(experimentAnalysis);
    }

    /**
     * 修改数据分析
     * 
     * @param experimentAnalysis 数据分析
     * @return 结果
     */
    @Override
    public int updateExperimentAnalysis(ExperimentAnalysis experimentAnalysis)
    {
        experimentAnalysis.setUpdateTime(DateUtils.getNowDate());
        experimentAnalysis.setUpdateBy(SecurityUtils.getUsername());
        return experimentAnalysisMapper.updateExperimentAnalysis(experimentAnalysis);
    }

    /**
     * 批量删除数据分析
     * 
     * @param analysisIds 需要删除的数据分析主键
     * @return 结果
     */
    @Override
    public int deleteExperimentAnalysisByAnalysisIds(Long[] analysisIds)
    {
        int deletedCount = 0;
        for (Long analysisId : analysisIds) {
            ExperimentAnalysis experimentAnalysis = experimentAnalysisMapper.selectExperimentAnalysisByAnalysisId(analysisId);
            experimentAnalysis.setDeleteBy(SecurityUtils.getUsername());
            experimentAnalysis.setDeleteTime(DateUtils.getNowDate());
            experimentAnalysis.setDelFlag(1);
            experimentAnalysisMapper.updateExperimentAnalysis(experimentAnalysis);
            deletedCount ++;
        }
        return deletedCount;
    }

    /**
     * 删除数据分析信息
     * 
     * @param analysisId 数据分析主键
     * @return 结果
     */
    @Override
    public int deleteExperimentAnalysisByAnalysisId(Long analysisId)
    {
        ExperimentAnalysis experimentAnalysis = experimentAnalysisMapper.selectExperimentAnalysisByAnalysisId(analysisId);
        experimentAnalysis.setDeleteBy(SecurityUtils.getUsername());
        experimentAnalysis.setDeleteTime(DateUtils.getNowDate());
        experimentAnalysis.setDelFlag(1);
        return experimentAnalysisMapper.updateExperimentAnalysis(experimentAnalysis);
    }
}
